home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 8.3 KB | 296 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWFont.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWFONT_H
- #include "FWFont.h"
- #endif
-
- #ifndef FWGC_H
- #include "FWGC.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWFXMATH_H
- #include "FWFxMath.h"
- #endif
-
- #ifndef FWGRUTIL_H
- #include "FWGrUtil.h"
- #endif
-
- #ifndef FWSTRMRW_H
- #include "FWStrmRW.h"
- #endif
-
- // ----- Macintosh Includes -----
-
- #if defined(FW_BUILD_MAC) && !defined(__TEXTUTILS__)
- #include <TextUtils.h>
- #endif
-
- #if defined(FW_BUILD_MAC) && !defined(__FONTS__)
- #include <Fonts.h>
- #endif
-
- #ifdef FW_BUILD_MAC
- #pragma segment FWGraphics_Font
- #endif
-
- //========================================================================================
- // Template instantiation
- //========================================================================================
-
- #include "FWGrRef.tpp"
-
- FW_DEFINE_AUTO_TEMPLATE(FW_TGrRefPtr, FW_HFont)
-
- #ifdef FW_USE_TEMPLATE_PRAGMAS
-
- #pragma template_access public
- #pragma template FW_TGrRefPtr<FW_HFont>
-
- #else
-
- template class FW_TGrRefPtr<FW_HFont>;
-
- #endif
-
- //========================================================================================
- // class FW_CFont
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CFont)
-
- //----------------------------------------------------------------------------------------
- // FW_PrivAcquireGrRep
- //----------------------------------------------------------------------------------------
-
- void FW_PrivAcquireGrRep(FW_HFont rep)
- {
- if (rep != 0)
- FW_PrivFont_Acquire(rep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_PrivReleaseGrRep
- //----------------------------------------------------------------------------------------
-
- void FW_PrivReleaseGrRep(FW_HFont rep)
- {
- if (rep != 0)
- FW_PrivFont_Release(rep);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::FW_CFont
- //----------------------------------------------------------------------------------------
-
- FW_CFont::FW_CFont(const FW_CString& fontName, FW_FontStyle fontStyle, FW_Fixed fontSize)
- {
- FW_PlatformError error;
- FW_HFont rep = FW_PrivFont_Create(fontName, fontStyle, fontSize, &error);
- FW_FailOnError(error);
- SetRep(rep);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::FW_CFont
- //----------------------------------------------------------------------------------------
-
- FW_CFont::FW_CFont(const FW_CFont& other) :
- FW_TGrRefPtr<FW_HFont>(other)
- {
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::FW_CFont
- //----------------------------------------------------------------------------------------
-
- FW_CFont::FW_CFont(FW_EStandardFonts std)
- {
- FW_PlatformError error;
- FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
- FW_FailOnError(error);
- SetRep(rep);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::FW_CFont
- //----------------------------------------------------------------------------------------
-
- FW_CFont::~FW_CFont()
- {
- FW_START_DESTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CFont& FW_CFont::operator=(const FW_CFont& other)
- {
- FW_TGrRefPtr<FW_HFont>::operator=(other);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::operator=
- //----------------------------------------------------------------------------------------
-
- FW_CFont& FW_CFont::operator=(FW_EStandardFonts std)
- {
- FW_PlatformError error;
- FW_HFont rep = FW_PrivFont_CreateStandard(std, &error);
- FW_FailOnError(error);
- SetRep(rep);
- return *this;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::GetFontName
- //----------------------------------------------------------------------------------------
-
- void FW_CFont::GetFontName(FW_CString& fontName) const
- {
- FW_PlatformError error;
- FW_PrivFont_GetName(fRep, fontName, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::SetFontName
- //----------------------------------------------------------------------------------------
-
- void FW_CFont::SetFontName(const FW_CString& fontName)
- {
- FW_PlatformError error;
- FW_PrivFont_SetName(fRep, fontName, &error);
- FW_FailOnError(error);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::GetFontMetrics
- //----------------------------------------------------------------------------------------
-
- void FW_CFont::GetFontMetrics(FW_HGDevice device, FW_CFontMetrics& fontMetrics) const
- {
- FW_FailOnError(FW_PrivGDev_GetFontMetrics(device, *this, fontMetrics));
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::GetFontMetrics
- //----------------------------------------------------------------------------------------
-
- void FW_CFont::GetFontMetrics(FW_CGraphicContext& gc, FW_CFontMetrics& fontMetrics) const
- {
- GetFontMetrics(gc.GetGraphicDevice(), fontMetrics);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::Copy
- //----------------------------------------------------------------------------------------
-
- FW_CFont FW_CFont::Copy() const
- {
- FW_PlatformError error;
- FW_HFont rep = FW_PrivFont_Copy(fRep, &error);
- FW_FailOnError(error);
-
- FW_CFont font;
- font.SetRep(rep);
- return font;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CFont::PlatformToODFFontStyle
- //----------------------------------------------------------------------------------------
- // It is a const& because on windows FW_PlatformFontStyle is a LOGFONT
-
- FW_FontStyle FW_CFont::PlatformToODFFontStyle(const FW_PlatformFontStyle& platformStyle)
- {
- FW_FontStyle fontStyle = FW_kPlain;
-
- #ifdef FW_BUILD_MAC
- if (platformStyle & bold)
- fontStyle += FW_kBold;
- if (platformStyle & italic)
- fontStyle += FW_kItalic;
- if (platformStyle & underline)
- fontStyle += FW_kUnderline;
- if (platformStyle & outline)
- fontStyle += FW_kOutline;
- if (platformStyle & shadow)
- fontStyle += FW_kShadow;
- if (platformStyle & extend)
- fontStyle += FW_kExtended;
- if (platformStyle & condense)
- fontStyle += FW_kCondensed;
- #endif
-
- #ifdef FW_BUILD_WIN
- if (platformStyle.lfItalic != 0)
- fontStyle += FW_kItalic;
- if (logFont.lfUnderline != 0)
- fontStyle += FW_kUnderline;
- if (logFont.lfStrikeOut != 0)
- fontStyle += FW_kStrikeOut;
- if (logFont.lfWeight == FW_BOLD)
- fontStyle += FW_kBold;
- #endif
-
- return fontStyle;
- }
-
- #ifdef FW_BUILD_MAC
- //----------------------------------------------------------------------------------------
- // FW_CFont::MacSetFontID
- //----------------------------------------------------------------------------------------
-
- void FW_CFont::MacSetFontID(short macFontID)
- {
- FW_PlatformError error;
- FW_PrivFont_MacSetFontID(fRep, macFontID, &error);
- FW_FailOnError(error);
- }
- #endif
-
- //----------------------------------------------------------------------------------------
- // operator <<
- //----------------------------------------------------------------------------------------
-
- FW_CWritableStream& operator << (FW_CWritableStream& stream, const FW_CFont& font)
- {
- FW_PlatformError error;
- FW_PrivFont_Write(font.fRep, stream, &error);
- FW_FailOnError(error);
- return stream;
- }
-
- //----------------------------------------------------------------------------------------
- // operator >>
- //----------------------------------------------------------------------------------------
-
- FW_CReadableStream& operator >> (FW_CReadableStream& stream, FW_CFont& font)
- {
- FW_PlatformError error;
- FW_HFont rep = FW_PrivFont_Read(stream, &error);
- FW_FailOnError(error);
- font.SetRep(rep);
- return stream;
- }
-
-